package boot

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
	"log"
)

type XormAdapter struct {
	*xorm.Engine
}

func NewXormAdapter() *XormAdapter {

	dsn := "root:123456@tcp(localhost:3306)/test?charset=utf8mb4&parseTime=True&loc=Local"
	if engine, err := xorm.NewEngine("mysql", dsn); err == nil {
		engine.DB().SetMaxIdleConns(5)
		engine.DB().SetMaxOpenConns(10)
		return &XormAdapter{Engine: engine}
	} else {
		log.Fatal(err)
	}
	return nil
}
